package cn.tedu.service;

import cn.tedu.pojo.Phone;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class TestJDBC2 {
    public static void main(String[] args) throws Exception {
        Class.forName("com.mysql.jdbc.Driver");
        String url = "jdbc:mysql://localhost:3307/py-school-db?characterEncoding=utf8&serverTimezone=Asia/Shanghai";
        Connection conn = DriverManager.getConnection(url,"root","123456");
        String sql = "select * from phone where name = ?";
        PreparedStatement ps = conn.prepareStatement(sql);
        ps.setString(1,"mate40");
        ResultSet rs = ps.executeQuery();
        Phone p=new Phone();
        while (rs.next()) {
            String name = rs.getNString(1);
            String color = rs.getNString(2);
            double price = rs.getDouble(3);
            p.setName(name);
            p.setColor(color);
            p.setPrice(price);
        }
        System.out.println(p);
        rs.close();
        ps.close();
        conn.close();
    }

}
